package com.huli.controller;

import com.huli.util.Result;
import com.huli.util.qiniuyun.QiniuUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.UUID;

@RestController
@RequestMapping("/upCaseImg")
public class UpCaseImgController {
    //病例图片上传
    @RequestMapping("/upImg")
    public Result upImg(@RequestParam(value = "imgFile")MultipartFile imgFile){
        System.out.println(imgFile);
        String originalFilename = imgFile.getOriginalFilename();
        int index = originalFilename.lastIndexOf(".");
        String extention = originalFilename.substring(index);
        String fileName = UUID.randomUUID().toString() + extention;
        try {
            QiniuUtils.upload2Qiniu(imgFile.getBytes(),fileName);
        }catch (IOException e){
            e.printStackTrace();
            return Result.error("上传失败");
        }
        return Result.success("上传成功",fileName);
    }
}
